package com.UdpRecieve.framework.listenner;

import com.UdpRecieve.framework.constant.ServletConstant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;


@WebListener
public class SysHttpSessionAttributeListener implements HttpSessionAttributeListener {

    Logger logger = LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        //存储name和session的对应关系
        if (se.getName().contains(ServletConstant.SESSION_KEY)){
            String userName = (String) se.getSession().getAttribute(se.getName());
            ServletConstant.OnlineUserList.put(userName,se.getSession().getId());
            logger.info("创建在线用户:"+userName);
        }
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {

    }
}
